mod cmd;
mod http;

use crate::cmd::{Opts, SubCommand};
use crate::http::{init_http, print_resp};
use clap::Parser;
use mimalloc::MiMalloc;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let opts = Opts::parse();
    init_http()?;
    let resp = match opts.subcmd {
        SubCommand::Get { url, headers } => http::get(&url, headers).await?,
        SubCommand::Post { url, headers, body } => http::post(&url, headers, body).await?,
    };

    print_resp(resp).await?;
    Ok(())
}
